#!/usr/bin/env python3
"""
Basic usage example for InCloud MCP Server
"""
import asyncio
import logging
from incloud_mcp_server.config import load_config
from incloud_mcp_server.swagger.client import SwaggerClient
from incloud_mcp_server.swagger.tool_generator import ToolGenerator

# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


async def main():
    """Demonstrate basic usage of InCloud MCP Server components"""
    
    try:
        # Load configuration
        config = load_config("config.yaml")
        logger.info("Configuration loaded successfully")
        
        # Create Swagger client
        swagger_client = SwaggerClient(config)
        
        # Discover available services
        logger.info("Discovering available services...")
        services = swagger_client.get_available_services()
        logger.info(f"Available services: {services}")
        
        # Get APIs for each enabled service
        for service_name in config.get_enabled_services().keys():
            logger.info(f"\nExploring service: {service_name}")
            
            # Get service APIs
            apis = swagger_client.get_service_apis(service_name)
            logger.info(f"Found {len(apis)} APIs in {service_name}")
            
            # Show first few APIs
            for api in apis[:3]:  # Show first 3 APIs
                logger.info(f"  {api['method']} {api['path']} - {api.get('summary', 'No summary')}")
        
        # Generate tools for a specific service
        logger.info("\nGenerating tools...")
        tool_generator = ToolGenerator(config)
        
        # Generate tools for the first enabled service
        enabled_services = list(config.get_enabled_services().keys())
        if enabled_services:
            service_name = enabled_services[0]
            tools = tool_generator.generate_service_tools(service_name)
            logger.info(f"Generated {len(tools)} tools for {service_name}")
            
            # Show tool information
            for tool in tools[:2]:  # Show first 2 tools
                logger.info(f"  Tool: {tool.__name__}")
                logger.info(f"    Doc: {tool.__doc__}")
                logger.info(f"    Signature: {tool.__signature__}")
        
        logger.info("\nBasic usage demonstration completed successfully!")
        
    except Exception as e:
        logger.error(f"Error during demonstration: {e}")
        raise


if __name__ == "__main__":
    asyncio.run(main())
